import socket
import tkinter as tk
from tkinter import messagebox

def add_contact():
    name = entry_name.get()
    address = entry_address.get()
    phone = entry_phone.get()
    
    if name and address and phone:
        client_socket.sendall(f"ADD {name},{address},{phone}".encode())
        response = client_socket.recv(1024).decode()
        messagebox.showinfo("Response", response)
    else:
        messagebox.showwarning("Warning", "All fields are required!")

def view_contacts():
    client_socket.sendall(b"VIEW")
    response = client_socket.recv(4096).decode()
    messagebox.showinfo("Contacts", response)

client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('localhost', 5000))

root = tk.Tk()
root.title("Personal Contact Manager")

tk.Label(root, text="Name").pack()
entry_name = tk.Entry(root)
entry_name.pack()

tk.Label(root, text="Address").pack()
entry_address = tk.Entry(root)
entry_address.pack()

tk.Label(root, text="Phone").pack()
entry_phone = tk.Entry(root)
entry_phone.pack()

tk.Button(root, text="Add Contact", command=add_contact).pack()
tk.Button(root, text="View Contacts", command=view_contacts).pack()

root.mainloop()
client_socket.close()